package com.zhoutian.service.Impl;

import com.zhoutian.dao.UserDAO;
import com.zhoutian.entity.User;
import com.zhoutian.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    UserDAO userDAO;

    @Override
    public boolean register(User user) {
        if (userDAO.save(user) > 0) {
            log.info("save success!");
            return true;
        }
        log.error("save error!");
        return false;
    }

    @Override
    public boolean login(User user) {
        if (userDAO.selectByNameAndPassword(user) != null) {
            log.info("login success");
            return true;
        }
        log.error("login error");
        return false;
    }

    @Override
    public boolean findDuplicate(User user) {
        if (userDAO.findByUsername(user) > 0) {
            return false;
        }
        return true;
    }

    @Override
    public Integer findUserIsMerchant(User user) {
        return userDAO.findIsMerchantByUser(user);
    }

    @Override
    public Integer findUserId(User user) {
        return userDAO.findUserIdByUsername(user);
    }
}
